
package com.wyzz.hr.action;

import java.util.List;
import org.apache.commons.lang.StringUtils;

import com.wyzz.hr.base.BaseAction;
import com.wyzz.hr.bo.IEmployeeBo;
import com.wyzz.hr.bo.IPositionBo;
import com.wyzz.hr.pojo.Employee;
import com.wyzz.hr.pojo.Position;
import com.wyzz.hr.spring.SpringBeanFactory;

public class DetailEmployeeInfo extends BaseAction {

	public DetailEmployeeInfo() {
	}

	public String execute() throws Exception {
		IEmployeeBo empBo = (IEmployeeBo) getBean("empBo");
		String fetch[] = { Employee.PROP_EMP_TYPE, Employee.PROP_EMP_DEPT_NO,
				Employee.PROP_EMP_LOCATION_NO, Employee.PROP_EMP_PB_NO };
		if (StringUtils.isNotEmpty(id))
			employee = empBo.loadEmp(id, fetch);
		if (employee == null)
			employee = empBo.loadEmp(getCurrentEmpNo(), fetch);
		String empMsn = employee.getEmpMsn();
		if (empMsn != null && !"".equals(empMsn))
			if (empMsn.startsWith("QQ:")) {
				connectionType = "1";
				connectionNo = empMsn.replace("QQ:", "");
			} else if (empMsn.startsWith("WW:")) {
				connectionType = "2";
				connectionNo = empMsn.replace("WW:", "");
			} else {
				connectionType = "0";
				connectionNo = empMsn;
			}
		IPositionBo posBo = (IPositionBo) SpringBeanFactory
				.getBean("positionBo");
		Position currPos = posBo.getPosByEmpNo(employee.getId(), new String[0]);
		if (currPos != null) {
			List allSubPosList = posBo.getAllSubPositions(null,
					new String[] { currPos.getId() });
			int allSub = 0;
			for (int i = 0; allSubPosList != null && i < allSubPosList.size(); i++) {
				Position pos = (Position) allSubPosList.get(i);
				if (pos.getPositionEmpNo() != null
						&& StringUtils.isNotEmpty(pos.getPositionEmpNo()
								.getId()))
					allSub++;
			}

			setAllEmpCount(allSub - 1);
			if (currPos.getPositionParentId() != null) {
				Position parentPos = posBo.getPosById(currPos
						.getPositionParentId().getId(),
						new String[] { Position.PROP_POSITION_EMP_NO });
				if (parentPos != null)
					employee.setEmpSupNo(parentPos.getPositionEmpNo());
			}
			empList = empBo.findDirectEmps(employee.getId());
			directEmpCount = empList != null ? empList.size() : 0;
			setDirectEmpCount(directEmpCount);
		}
		return "success";
	}

	public Employee getEmployee() {
		return employee;
	}

	public void setEmployee(Employee employee) {
		this.employee = employee;
	}

	public List getEmpList() {
		return empList;
	}

	public void setEmpList(List empList) {
		this.empList = empList;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public int getAllEmpCount() {
		return allEmpCount;
	}

	public void setAllEmpCount(int allEmpCount) {
		this.allEmpCount = allEmpCount;
	}

	public int getDirectEmpCount() {
		return directEmpCount;
	}

	public void setDirectEmpCount(int directEmpCount) {
		this.directEmpCount = directEmpCount;
	}

	public String getConnectionType() {
		return connectionType;
	}

	public void setConnectionType(String connectionType) {
		this.connectionType = connectionType;
	}

	public String getConnectionNo() {
		return connectionNo;
	}

	public void setConnectionNo(String connectionNo) {
		this.connectionNo = connectionNo;
	}

	private static final long serialVersionUID = 0x1c2f86bbL;
	private Employee employee;
	private String connectionType;
	private String connectionNo;
	private List empList;
	private String id;
	private int directEmpCount;
	private int allEmpCount;
}
